﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.AspNet.SignalR;

namespace ERPStore.Web.Logging
{
	public class LoggerConnection : PersistentConnection 
	{
		internal static void PushMessage(string message)
		{
			var cnx = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetConnectionContext<LoggerConnection>();
			if (cnx != null)
			{
				cnx.Connection.Broadcast(message);
			}
		}

		protected override bool AuthorizeRequest(IRequest request)
		{
			var apiKey = request.Headers["apikey"];
			return GlobalConfiguration.Configuration.Settings.ApiToken.Equals(apiKey);
		}

	}
}
